//
//  LoginViewController.m
//  Futures
//
//  Created by Cheng on 2017/6/29.
//  Copyright © 2017年 Cheng. All rights reserved.
//

#import "LoginViewController.h"
#import "MineViewModel.h"
#import "LoginTextField.h"

@interface LoginViewController ()

@property (weak, nonatomic) IBOutlet LoginTextField *accountView;

@property (weak, nonatomic) IBOutlet LoginTextField *passwordView;

@property (weak, nonatomic) IBOutlet UITextField *accountTextField;

@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"登陆";
    [self.passwordView setLoginTextFieldWithTitle:@"密码" placeholder:@"请输入登录密码"];
    
    self.accountView.textField.text = @"czx";
    self.passwordView.textField.text = @"123456";
    [self.passwordView.textField setSecureTextEntry:YES];
    self.accountView.textField.keyboardAppearance = UIKeyboardAppearanceDark;
    self.passwordView.textField.keyboardAppearance = UIKeyboardAppearanceDark;
//    [self addToolbarOnKeyboard:self.accountView.textField];
//    [self addToolbarOnKeyboard:self.passwordView.textField];
    
    //去除导航栏下方的横线
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init]
                                                  forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc]init]];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[UIView new]];
}

- (IBAction)clickLogin:(id)sender {
    [SVProgressHUD show];
    [MineViewModel requestLogin:self.accountView.textField.text password:self.passwordView.textField.text block:^(User *user) {
        [SVProgressHUD dismiss];
        if (user.ReturnCode == 1) {
            [self.view makeToast:@"登录成功"];
            UIViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateInitialViewController];
            [self presentViewController:vc animated:NO completion:nil];
        }else{
            showAlert(@"登录失败");
        }
    }];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.barTintColor = UICOLOR_RGB_Alpha(0x0d0d0d, 1);
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBar.barTintColor = UICOLOR_RGB_Alpha(0x202020, 1);
}


//- (void)selfDissmiss{
//    NSArray *viewcontrollers=self.navigationController.viewControllers;
//    if (viewcontrollers.count>1) {
//        if ([viewcontrollers objectAtIndex:viewcontrollers.count-1]==self) {
//            //push方式
//            [self.navigationController popViewControllerAnimated:YES];
//        }
//    }
//    else{
//        //present方式
//        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
//    }
//}


@end
